﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FrameWork;
using FrameWork.web.Code;
using FrameWork.Entity;
using FrameWork.Components;
using FrameWork.WebControls;

namespace FrameWork.web.Module.ITMS.KnowledgeBase.KBCollect
{
    public partial class KBCollect : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                rbListCollec.SelectedIndex = 2;

                //绑定故障分类
                sys_FieldValue sfTroubType = new sys_FieldValue();
                sfTroubType.V_F_Key = "TroubType";
                its_FieldValueCs sfTroubTypeCs = new its_FieldValueCs();
                DataTable dtTroubType = sfTroubTypeCs.Field_SelectInfoByF_Key(sfTroubType);

                DataRow dr1 = dtTroubType.NewRow();
                dr1["V_Text"] = "请选择";
                dr1["ValueID"] = -1;
                dtTroubType.Rows.InsertAt(dr1, 0);

                this.drpServTrobType.DataTextField = "V_Text";
                this.drpServTrobType.DataValueField = "ValueID";
                this.drpServTrobType.DataSource = dtTroubType;
                this.drpServTrobType.DataBind();
                //绑定问题分类
                sys_FieldValue sfProbType = new sys_FieldValue();
                sfProbType.V_F_Key = "ProbType";
                its_FieldValueCs sfProbTypeCs = new its_FieldValueCs();
                DataTable dtsfProbType = sfProbTypeCs.Field_SelectInfoByF_Key(sfProbType);
                
                DataRow dr2 = dtsfProbType.NewRow();
                dr2["V_Text"] = "请选择";
                dr2["ValueID"] = -1;
                dtsfProbType.Rows.InsertAt(dr2, 0);
                
                this.drpServProbType.DataTextField = "V_Text";
                this.drpServProbType.DataValueField = "ValueID";
                this.drpServProbType.DataSource = dtsfProbType;
                this.drpServProbType.DataBind();

                lblCollec.Text = "0";
                lblServProbType.Text = "-1";
                lblServTrobType.Text = "-1";
                lblDocNo.Text = "";
                BindServerDoc();
            }
        }

        /// <summary>
        /// 绑定全部服务单
        /// </summary>
        private void BindServerDoc()
        {
            its_ServiceDocCs itcs = new its_ServiceDocCs();
            its_ServiceDoc its = new its_ServiceDoc();
            its.Done = Convert.ToInt32(lblCollec.Text.Trim());
            its.ServTrobType = Convert.ToInt32(lblServTrobType.Text.Trim());
            its.ServProbType = Convert.ToInt32(lblServProbType.Text.Trim());
            its.ServDocNo = lblDocNo.Text.Trim();
            ArrayList arr = new ArrayList();
            arr = itcs.ServiceDoc_KnowledgeSelect(its, PagerSolve.CurrentPageIndex, PagerSolve.PageSize);
            GVUnsolve.DataSource = (DataTable)arr[1];
            GVUnsolve.DataBind();
            PagerSolve.RecordCount = (int)arr[0];
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            PagerSolve.CurrentPageIndex = 1;
            lblCollec.Text = rbListCollec.SelectedValue.Trim();
            lblServProbType.Text = drpServProbType.SelectedValue.Trim();
            lblServTrobType.Text = drpServTrobType.SelectedValue.Trim();
            lblDocNo.Text = txtDocNo.Text.Trim();
            BindServerDoc();
        }

        protected void PagerSolve_PageChanged(object sender, EventArgs e)
        {
            BindServerDoc();
        }

        protected void lbtUnsolve_Click(object sender, EventArgs e)
        {
            try
            {

                //if (((LinkButton)sender).Parent.Parent.Parent.Parent.ID == "GVUnsolve")
                //{
                //    txtUid.Text = ((Label)((GridViewRow)((LinkButton)sender).Parent.Parent).FindControl("labUID")).Text.Trim();
                //    showTR();
                //    GetDocDetail(txtUid.Text.Trim());
                //}
                //else
                //{
                //    hindTR();
                //}
                string strServDocNo = ((LinkButton)sender).Text;
                TxtServerDocNo.Text = strServDocNo;
                its_ServiceDocCs sdCs = new its_ServiceDocCs();
                its_ServiceDoc sd = new its_ServiceDoc();
                sd.ServDocNo = strServDocNo;
                DataTable dt = sdCs.ServiceSelect(sd);
                //txtServDocNo.Text = strServDocNo;
                TxtRepContext.Text = dt.Rows[0]["RepContent"].ToString();
                TxtRepTitle.Text = dt.Rows[0]["RepTitle"].ToString();
                TxtSolution.Text = dt.Rows[0]["ItemMessage"].ToString().Replace("\\n", "\n");
                TxtSolution.Text = TxtSolution.Text.Replace("\\t", "\t");

                //drpServTrobType.SelectedValue = dt.Rows[0]["ServTrobType"].ToString();
                //drpServProbType.SelectedValue = dt.Rows[0]["ServProbType"].ToString();
            }
            catch
            {
                //
            }
           
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            sys_UserTable ut = BusinessFacade.sys_UserDisp(Common.Get_UserID);
            int User_ID = ut.UserID;
            string User_Name = ut.U_CName.Trim();
            
            if (User_Name.Trim() == "")
            {
                EventMessage.MessageBox(1, "操作失败", "操作失败,无法获取当前归纳人员信息!", Icon_Type.Alert, Common.GetHomeBaseUrl("KBCollect.aspx"));
                return;
            }

            its_KnowledgeBaseCs itkc = new its_KnowledgeBaseCs();
            its_KnowledgeBaseEntity kut = new its_KnowledgeBaseEntity();
            int KID_Value = (int)Common.sink(txtKID.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            kut.KID = KID_Value;
            kut.Status = 1;
            kut.Subject = txtSubject.Text.Trim();
            kut.Content = txtContent.Text.Trim();
            kut.KeyWord = txtKeyWord.Text.Trim();
            kut.Attachment = txtAttachment.Text.Trim();
            kut.DocNo = TxtServerDocNo.Text.Trim();
            kut.UserID = User_ID;
            kut.UserName = User_Name;
            kut.CollateDAT = DateTime.Now;
            itkc.KnowledgeBase_KBCollect(kut);
        }
    }
}
